package com.songcha.module_home.ui.activity.image

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.widget.FrameLayout
import android.widget.ImageView
import com.alibaba.android.arouter.facade.annotation.Route
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.target.CustomTarget
import com.bumptech.glide.request.target.SimpleTarget
import com.bumptech.glide.request.transition.Transition
import com.songcha.library_base.base.BaseActivity
import com.songcha.library_common.util.GlideUtil
import com.songcha.library_common.util.ScreenUtil
import com.songcha.module_home.R


@Route(path="/home/ImageActivity")
class ImageActivity:BaseActivity() {

    override fun getLayoutId(): Int {
        return R.layout.home_activity_image
    }

    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)

        var url=""
        //var aspect_ratio=1f
        intent?.let {
            url=it.getStringExtra("url")?:""
            //aspect_ratio=it.getFloatExtra("aspect_ratio",1f)
        }

        if(url.isBlank()) return

        val iv = findViewById<ImageView>(R.id.home_iv)

        /*val target=object : CustomTarget<Bitmap>(){
            override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
                iv.layoutParams=iv.layoutParams.apply {
                    width=ScreenUtil.getScreenWidth()
                    val ar=resource.width/(resource.height*1.0f)
                    height=(ScreenUtil.getScreenWidth()/ar).toInt()
                }
                iv.setImageBitmap(resource)
            }

            override fun onLoadCleared(placeholder: Drawable?) {

            }

        }
        Glide.with(this).asBitmap().load(url).into(target)*/

        GlideUtil.loadCustomImageView(iv,url,ScreenUtil.getScreenWidth(), DiskCacheStrategy.NONE,{
            w,h->FrameLayout.LayoutParams(w,h)
        })
    }

    override fun isImmerseStatusBar(): Boolean {
        return true
    }

}